<template>
	<view>
	  <rich-text :nodes="htmlString"></rich-text>
	</view>
</template>

<script>
import { ref, onMounted } from 'vue';
import decRegisterApi from "/api/dec/decUser/decRegisterApi";

export default {
  props: {
    page: {
      type: String,
      default: ''
    }
  },
  setup(props) {
    const htmlString = ref(''); // 存储原始 HTML 字符串

    // 获取协议内容的函数
    function fetchPolicy() {
      decRegisterApi.GetPolicy_API(props.page).then((res) => {
		htmlString.value = res;
		console.log("获取协议内容成功",htmlString.value);
      }).catch((err) => {
        console.error('获取协议内容失败', err);
      });
    }

    // 页面加载时获取协议内容
    onMounted(() => {
      fetchPolicy();

      // 设置页面标题
      uni.setNavigationBarTitle({
        title: props.page === 'agreement' ? '服务协议' : '隐私政策'
      });
    });

    return {
	  htmlString,
      fetchPolicy
    };
  }
};
</script>

<style scoped>
.policy-container {
  padding: 20px;
}
</style>